<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="学号" prop="studentNo">
        <el-input
          v-model="queryParams.studentNo"
          placeholder="请输入学号"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="班级" prop="className">
        <el-input
          v-model="queryParams.className"
          placeholder="请输入班级名称"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="学生姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入学生姓名"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="宿舍栋号" prop="buildingNo">
        <el-select
          v-model="queryParams.buildingNo"
          placeholder="宿舍栋号"
          clearable
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="dict in buildingNoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="楼层" prop="storey">
        <el-select
          v-model="queryParams.storey"
          placeholder="宿舍楼层"
          clearable
          size="small"
          style="width: 180px"
        >
          <el-option
            v-for="dict in storeyOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="宿舍号" prop="dormitoryNo">
        <el-input
          v-model="queryParams.dormitoryNo"
          placeholder="请输入宿舍号"
          clearable
          size="small"
          style="width: 180px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="打卡日期" prop="accessDate">
        <el-date-picker
          v-model="queryParams.accessDate"
          size="small"
          style="width: 140px"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <el-form-item label="打卡类型" prop="flag">
        <el-select label="打卡类型" v-model="queryParams.flag" 
        clearable
        size="small" placeholder="打卡类型">
          <el-option :key="1" label="人工打卡" value="1"></el-option>
          <el-option :key="2" label="考勤机打卡" value="2"></el-option>
          <el-option :key="3" label="请假打卡" value="3"></el-option>
          <el-option :key="4" label="未打卡" value="4"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['smartdor:exception:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['smartdor:exception:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['smartdor:exception:remove']"
        >删除</el-button>
      </el-col>

    </el-row>

    <el-table v-loading="loading" :data="processList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="学号" align="center" prop="studentNo" :show-overflow-tooltip="true" />
      <el-table-column label="班级" align="center" prop="className" :show-overflow-tooltip="true" />
      <el-table-column label="学生姓名" align="center" prop="studentName" :show-overflow-tooltip="true" />
      <el-table-column label="宿舍栋号" align="center" prop="buildingNo" :formatter="buildingNoFormat" />
      <el-table-column label="楼层" align="center" prop="storey" :formatter="storeyFormat" />
      <el-table-column label="宿舍号" align="center" prop="dormitoryNo" :show-overflow-tooltip="true" />
      <el-table-column label="打卡时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打卡方式" align="center" prop="flag" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.flag==1" type="success">人工打卡</el-tag>
          <el-tag v-if="scope.row.flag==2" type="info">考勤机打卡</el-tag>
          <el-tag v-if="scope.row.flag==3" type="warning">请假打卡</el-tag>
          <el-tag v-if="scope.row.flag==4" type="danger">未打卡</el-tag>
          </template>
        </el-table-column>

      <!-- <el-table-column label="修改时间" align="center" prop="modifyTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime) }}</span>
        </template>
      </el-table-column> -->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="650px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-form-item label="学号" prop="studentNo">
            <el-input v-model="form.studentNo" placeholder="请输入学号"/>
          </el-form-item>
        </el-col>
       <el-col :span="1.5">
        <el-form-item label="班级" prop="classId">
           <el-select v-model="form.classId" clearable  placeholder="请选择">
             <el-option
                     v-for="item1 in classOptions"
                     :key="item1.id"
                     :label="item1.className"
                     :value="item1.id"
             />
           </el-select>
         </el-form-item>
        </el-col>
        <el-col :span="1.5">
          <el-form-item label="学员姓名" prop="studentName">
            <el-input v-model="form.studentName" placeholder="请输入学员姓名"  />
          </el-form-item>
        </el-col>
        <el-col :span="1.5">
         <el-form-item label="处理状态" prop="absenceProcessStatus">
            <el-select v-model="form.absenceProcessStatus"  placeholder="请选择">
              <el-option
                      v-for="dict in processStatusOptions"
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
         </el-col>
         <el-col :span="24">
          <el-form-item label="处理描述" prop="processDesc">
            <el-input type="textarea"  v-model="form.processDesc" placeholder="请输入处理描述" />
          </el-form-item>
         </el-col>


     </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSdException, getSdException, addSdException, updateSdException, changeSdExceptionStatus, delSdException} from "@/api/smartdor/sdattenceexception";
import { listAllBClass } from "@/api/basedata/bclass";
import { getNormalSdAttence} from "@/api/smartdor/normalsdattence";

export default {
  name: "SdException",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      //列表
      processList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 班级
      classOptions: [],
      // 状态数据字典
      processStatusOptions: [],
      buildingNoOptions: [],
      storeyOptions: [],
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        studentNo: undefined,
        studentName: undefined,
        className: undefined,
        absenceProcessStatus: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studentNo: [
          { required: true, message: "学号不能为空", trigger: "blur" }
        ],
        absenceProcessStatus: [
          { required: true, message: "处理状态不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.listAllBClass();
    this.getDicts("sys_building").then(response => {
      this.buildingNoOptions = response.data;
    });
    this.getDicts("sys_storey").then(response => {
      this.storeyOptions = response.data;
    });
    this.getDicts("sys_normal_disable").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("absence_process_status").then(response => {
      this.processStatusOptions = response.data;
    });
  },
  methods: {
    /** 查询班级列表 */
    getList() {
      this.loading = true;
      getNormalSdAttence(this.queryParams).then(response => {
          this.processList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    listAllBClass(){
      listAllBClass().then(response => {
        this.classOptions = response.data;
      });
    },
    // 字典设备状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 字典设备状态字典翻译
    processStatusFormat(row, column) {
      return this.selectDictLabel(this.processStatusOptions, row.absenceProcessStatus);
    },

    buildingNoFormat(row, column) {
      return this.selectDictLabel(this.buildingNoOptions, row.buildingNo);
    },
    storeyFormat(row, column) {
      return this.selectDictLabel(this.storeyOptions, row.storey);
    },
    bdormitoryFormat(row, column) {
      return this.selectDictLabel(this.bdormitoryOptions, row.bdormitoryId);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        studentNo: undefined,
        studentName: undefined,
        classId:undefined,
        className: undefined,
        absenceProcessStatus: undefined,
        processDesc:undefined,
        status: "1",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
